﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Arizu.Repository;
using System.Text;
using System.Web.SessionState;

namespace AiRiZu.User
{
    public class SystemMessage : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            AirizuMessage aMessage = AirizuMessage.CreateInstance();

            if (context.Session["logId"] == null)
            {
                return;
            }

            DataTable dt = aMessage.GetSysMesage(int.Parse(context.Session["logId"].ToString()));
            StringBuilder sBuilder = new StringBuilder();

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sBuilder.Append(dt.Rows[i]["Message"].ToString()).Append("\n");
                }
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write(sBuilder.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
